package com.yida.admin;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.yida.bean.blog;
import com.yida.bean.blogtype;
import com.yida.service.serverblog;

@Controller
public class blogs {

	@Autowired
	public serverblog service;
	
	@RequestMapping("/admin/blogs")
	public String index(Model mode,Integer page,blog blog,Integer type) {  
		Integer pages = 1 ;
		if (page!=null) {
			pages = page;
		}
		//根据条件查出博客
		List<blog> bloglist =  service.selectBlogadmin(pages,blog,type);
		//根据条件查出博客数量
		Integer blogsum =  service.selectBlogsumadmin(blog, type);
		//查询分类
		List<blogtype> types = service.selectblogtypeservice();
	
		
		
		
		if (blog.getTitle()!=null) {
		//放条件查询
		mode.addAttribute("title", blog.getTitle());
		}
		if (type!=null) {
		//放条件查询
			mode.addAttribute("type", type);
		}
		if (blog.getPublished()!=null) {
		//放条件查询
				mode.addAttribute("Published", blog.getPublished()); 
		}else {
			    mode.addAttribute("Published", 0);
		}
		//当前页数
		mode.addAttribute("pages", blogsum);
		//总页数
		mode.addAttribute("cpage", pages);
		//存放查出的博客
		mode.addAttribute("bloglist", bloglist);
		//存放类型
		mode.addAttribute("types", types);
		
		return "admin/blogs";
	}
	
	
}

